#include<iostream>
using namespace std;
class Demo;

int global;

class Expt
{
		public:
				Demo * d;
				Expt(){ d=NULL;}
				~Expt(){d=NULL;}

				const char * reason() const
				{
						return "Expt";
				}
};

class Demo
{
		public:
				int val;
				Demo()
				{
						val=4;
						cout<<"demo construct"<<endl;
				}

				~Demo()
				{

						val=0;
						cout<<"demo destruct"<<endl;
				}
};


void fun()
{
		Demo d;
		global= *(&d.val);
		cout<<"global in fun 1: "<<global<<endl;
		
		cout<<"d.val addr   "<<&d.val<<endl;
		cout<<d.val<<endl;
		Expt e;
		e.d=&d;
		throw e;
}


int main()
{
		try
		{
				fun();
		}

		catch(Expt e)
		{
			cout<<&(e.d->val)<<endl;
			cout<<*(&(e.d->val))<<endl;
			cout<<e.d->val<<endl;
			cout<<e.reason()<<endl;
		}

		cout<<"bye"<<endl;
		return 0;
}
